package cn.crm.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mysql.fabric.xmlrpc.base.Data;

import cn.crm.Service.IUserService;
import cn.crm.common.ServerResponse;
import cn.crm.entity.User;

@Controller
@RequestMapping(value="user")
public class UserController {

	@Autowired
	private IUserService userservice;
	
	@RequestMapping(value="touserpage")
	public String topage(){
		return "user/user_list";
	}
	
	
	@RequestMapping(value="pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,User user,Data time){
		return userservice.pageList(page,limit,user);
	}
	
	
	@RequestMapping(value="deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids){
		return userservice.deleteAll(ids);
	}
	
	@RequestMapping(value="toAddPage")
	public String toaddpage(){
		return "user/user_insert";
	}
	
	
	@RequestMapping(value="insert")
	@ResponseBody
	public ServerResponse insert(User user,String roles){
		System.err.println(user);
		System.err.println(roles);
		return userservice.insert(user,roles);
	}
	
	@RequestMapping(value="login")
	@ResponseBody
	public ServerResponse login(String name,String password,HttpSession session){
		
		return userservice.login(name,password,session);
	}
	
	@RequestMapping(value="deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id){
		return userservice.deleteById(id);
	}
	
	@RequestMapping(value="toupdatepage")
	public String toupdatepage(){
		return "user/user_update";
	}
	
	@RequestMapping(value="selectRolesandUsers")
	@ResponseBody
	public ServerResponse selectRolesandUsers(Integer userId){
		System.err.println(userId);
		return userservice.selectRolesandUsers(userId);
	}
	
	@RequestMapping(value="update")
	@ResponseBody
	public ServerResponse update(User user,String roles){
		return userservice.update(user,roles);
	}
	
	@RequestMapping(value="selectIds")
	@ResponseBody
	public ServerResponse selectIds(){
		return userservice.selectIds();
	}
}
